home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / SPEZIAL / GEMVIEW / UTILITY / GEM_VIEW.101 / GEM_VIEW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-20  |  4.0 KB  |  222 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tos.h>
  5. #include <aes.h>
  6. #include <view.h>
  7.  
  8. #define WAIT_TIMER    10000
  9.  
  10.  
  11.  
  12.  
  13. int                 appl_id, menu_id, wi_id = 0,
  14.                  msg[8], ToAccApp = 0;
  15. long             tmp_count = 0;
  16.  
  17.  
  18. /* ----- Cookie Jar -------------------------------------------------------- */
  19.  
  20. typedef struct
  21. {
  22.     long    id,
  23.             *ptr;
  24. } COOKJAR;
  25.  
  26.  
  27.  
  28.  
  29. void MessageSend(int sendto, int msg0, char *msg3, int msg5, int msg6, int msg7)
  30. {
  31.   int     msg[8];
  32.   
  33.   msg[0] = msg0;
  34.   msg[1] = appl_id;
  35.   msg[2] = 0;
  36.   *(char**)&msg[3] = msg3; /* ACHTUNG: Unter 'MiNT' GLOBAL reservieren! */
  37.   msg[5] = msg5;
  38.   msg[6] = msg6;
  39.   msg[7] = msg7;
  40.   appl_write(sendto, 16, msg);
  41. }
  42.  
  43.  
  44.  
  45. long *get_cookie(long cookie)
  46. {
  47.     long    sav;
  48.     COOKJAR    *cookiejar;
  49.     int        i = 0;
  50.  
  51.     sav = Super((void *)1L);
  52.     if(sav == 0L)
  53.         sav = Super(0L);
  54.     cookiejar = *((COOKJAR **)0x05a0L);
  55.     if(sav != -1L)
  56.         Super((void *)sav);
  57.     if(cookiejar)
  58.     {
  59.         while(cookiejar[i].id)
  60.         {
  61.             if(cookiejar[i].id == cookie)
  62.                 return(cookiejar[i].ptr);
  63.             i++;
  64.         }
  65.     }
  66.     return(0L);
  67. }
  68.  
  69.  
  70.  
  71. void getfile(char **input, long *length)
  72. {
  73.     char    path[220];
  74.     char    file[20], *s;
  75.     int     ret, ex;
  76.     
  77.     *input = NULL;
  78.     *length = 0;
  79.     path[0] = '\0';
  80.     file[0] = '\0';
  81.     ret = fsel_input(path, file, &ex);
  82.     if (ret == 0 || ex == 0)
  83.         return;
  84.     
  85.     s = strrchr(path, '\\');
  86.     if (s == NULL)
  87.         return;
  88.     
  89.     strcpy(s+1, file);
  90.     
  91.     *length = strlen(path) + 1;
  92.     *input = malloc(*length + 10L);
  93.     if (*input == NULL) {
  94.         return;
  95.     }
  96.     strcpy(*input, path);
  97. }
  98.  
  99.  
  100.  
  101.  
  102. MessageWait(int *msg, int wait)
  103. {
  104.     int        event, dummy;
  105.   
  106.     msg[0] = 0;
  107.     event = evnt_multi(MU_MESAG|MU_TIMER, 0, 0, 0,
  108.                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109.                         msg, wait, 0, &dummy, &dummy,
  110.                         &dummy, &dummy, &dummy, &dummy);
  111.     if (event & MU_MESAG) {
  112.         if ((msg[0] & 0xFF00) == VIEW_FILE)
  113.             return(1);
  114.         if (msg[0] == AC_OPEN)
  115.             return(0);
  116.         if (msg[0] == AC_CLOSE)
  117.             return(0);
  118.     }
  119.     if (!(event & MU_MESAG))
  120.         tmp_count++;
  121.     
  122.     return(0);
  123. }
  124.  
  125. void main(void)
  126. {
  127.     char   *input;
  128.     long    length;
  129.     
  130.     tmp_count = 0;
  131.     appl_id = appl_init();
  132.     menu_register(appl_id, "  Send View!");
  133.     input = (char*)get_cookie('View');
  134.     if (input != NULL)
  135.         ToAccApp = appl_find(input);
  136.     msg[0] = 0;
  137.     while(1)
  138.     {
  139.         if (msg[0] == 0)
  140.             evnt_mesag(msg);
  141.         switch(msg[0])
  142.         {
  143.             case AC_OPEN:
  144.                 if (wi_id == 0) {
  145.                     /* Neuladen! */
  146.                     getfile(&input, &length);
  147.                     if (input == NULL)
  148.                     {
  149.                         msg[0] = 0;
  150.                         break;
  151.                     }
  152.                     input[length] = '\0';
  153.                     /* Neues File anzeigen lassen */
  154.                     MessageSend(ToAccApp, VIEW_FILE, input, 0, 0, 0);
  155.                     wi_id = 0;
  156.                     if (MessageWait(msg, WAIT_TIMER) == 0) {
  157.                         free(input);
  158.                         break;
  159.                     }
  160.                     free(input);
  161.                     if (msg[0] == VIEW_OPEN)
  162.                         wi_id = msg[7];
  163.                 } else {
  164.                     /* Ersetzen oder Löschen! */
  165.                     if (form_alert(0, "[0][ | Send View! | ][ Replace | Delete ]") == 1) {
  166.                         /* Ersetzen! */
  167.                         getfile(&input, &length);
  168.                         if (input == NULL)
  169.                         {
  170.                             msg[0] = 0;
  171.                             break;
  172.                         }
  173.                         input[length] = '\0';
  174.                         /* Altes File durch neues File ersetzen */
  175.                         MessageSend(ToAccApp, VIEW_FILE, input, 0, 0, wi_id);
  176.                         wi_id = 0;
  177.                         if (MessageWait(msg, WAIT_TIMER) == 0) {
  178.                             free(input);
  179.                             break;
  180.                         }
  181.                         free(input);
  182.                     
  183.                         if (msg[0] == VIEW_CLOSED || msg[0] == VIEW_OPEN) {
  184.                             if (msg[0] == VIEW_CLOSED)
  185.                                 if (MessageWait(msg, WAIT_TIMER) == 0)
  186.                                     break;
  187.                             if (msg[0] == VIEW_OPEN)
  188.                                 wi_id = msg[7];
  189.                         }
  190.                     } else {
  191.                         /* Fenster schließen */
  192.                         MessageSend(ToAccApp, VIEW_FILE, NULL, 0, 0, wi_id);
  193.                         wi_id = 0;
  194.                         if (MessageWait(msg, WAIT_TIMER) == 0)
  195.                             break;
  196.                         wi_id = 0;
  197.                     }
  198.                 }
  199.                 msg[0] = 0;
  200.                 break;
  201.  
  202.             case AC_CLOSE:
  203.                 wi_id = 0;
  204.                 msg[0] = 0;
  205.                 break;
  206.             
  207.             case VIEW_OPEN:
  208.                 wi_id = msg[7];
  209.                 msg[0] = 0;
  210.                 break;
  211.             
  212.             case VIEW_CLOSED:
  213.                 wi_id = 0;
  214.                 msg[0] = 0;
  215.                 break;
  216.             
  217.             default:
  218.                 msg[0] = 0;
  219.         }
  220.     }
  221. }
  222.